
import { App, Adapter } from "../lib.letusbit/lib"
import { Renderer } from "../lib.letusbit/renderer/adapter";
import { myloop } from "./myloop";



function start()
{
    //还需要一些锁定滚动的代码
    document.body.style.margin="0px";//消除body黑边

    //初始化一个webgl环境
    var root = document.createElement("canvas");
    root.style.position = "absoulute";
    root.style.width = "100%";
    root.style.height = "100%";
    document.body.appendChild(root);
    var webgl = root.getContext("webgl");
    //初始化canvas 绘制区域
    //线性缩放的情况只需要调节canvas的 width 和 height
    root.width = root.clientWidth/1;
    root.height = root.clientHeight/1;


    if (webgl == null)
    {
        document.body.removeChild(root);
        var span = document.createElement("span");
        span.textContent = "Not support webgl.";
        document.body.compareDocumentPosition(span);
        return;
    }

    //交给usercode
    
 
    let app = new App.Framework(new myloop(), webgl);

    window.addEventListener("resize", (ev: UIEvent) =>
    { 
        //初始化canvas 绘制区域
        root.width = root.clientWidth/1;
        root.height = root.clientHeight/1;
        app.ResizeCanvas();
    });

    app.Init();

}

window.onload = start;